﻿namespace LogWiritter
{
    using System.IO;

    public class FileBuilder
    {
        /// <summary>
        /// Create empty file
        /// </summary>
        /// <param name="path">Path to file</param>
        public void BuildEmptyFile(string path)
        {
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            m_filePath = path;
            using (FileStream fs = File.Create(path)) { }          
        }

        /// <summary>
        /// Write message into file
        /// </summary>
        /// <param name="message">Message</param>
        public void WriteMessage(string message)
        {
            if (File.Exists(m_filePath))
            {
                using (StreamWriter writter = new StreamWriter(m_filePath,true))
                {
                    writter.WriteLine(message);
                }
            } 
        }

        /// <summary>
        /// Read Message from file
        /// </summary>
        /// <returns>Message from fime</returns>
        public string ReadMessage()
        {
            string rezult = string.Empty;

            if (File.Exists(m_filePath))
            {
                using (StreamReader reader = new StreamReader(m_filePath))
                {
                    rezult = reader.ReadToEnd();
                }
            }
            return rezult;
        }

        private string m_filePath = string.Empty;
    }
}
